package com.honeyms.project.blog.blogcomment.controller;

import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.honeyms.framework.aspectj.lang.annotation.Log;
import com.honeyms.framework.aspectj.lang.enums.BusinessType;
import com.honeyms.project.blog.blogcomment.domain.BlogComment;
import com.honeyms.project.blog.blogcomment.domain.BlogCommentClose;
import com.honeyms.project.blog.blogcomment.service.IBlogCommentService;
import com.honeyms.framework.web.controller.BaseController;
import com.honeyms.framework.web.domain.AjaxResult;
import com.honeyms.common.utils.poi.ExcelUtil;
import com.honeyms.framework.web.page.TableDataInfo;

/**
 * 评论详情Controller
 * 
 * @author honeyms
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/blog/blogcomment")
public class BlogCommentController extends BaseController
{
	
    private String prefix = "blog/blogcomment";

    @Autowired
    private IBlogCommentService blogCommentService;

    @RequiresPermissions("blog:blogcomment:view")
    @GetMapping()
    public String blogcomment()
    {
        return prefix + "/blogcomment";
    }

    /**
     * 查询评论详情列表
     */
    @RequiresPermissions("blog:blogcomment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BlogCommentClose blogComment)
    {
        startPage();
        List<BlogCommentClose> list = blogCommentService.selectBlogCommentCloseList(blogComment);
        return getDataTable(list);
    }
    
    /**
     * 查询评论详情列表
     */
    @PostMapping("/childlist")
    @ResponseBody
    public TableDataInfo childlist(BlogCommentClose blogComment)
    {
    	startPage();
    	List<BlogCommentClose> list = blogCommentService.selectBlogCommentCloseList(blogComment);
    	return getDataTable(list);
    }

    /**
     * 导出评论详情列表
     */
    @RequiresPermissions("blog:blogcomment:export")
    @Log(title = "评论详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BlogComment blogComment)
    {
        List<BlogComment> list = blogCommentService.selectBlogCommentList(blogComment);
        ExcelUtil<BlogComment> util = new ExcelUtil<BlogComment>(BlogComment.class);
        return util.exportExcel(list, "blogcomment");
    }

    /**
     * 新增评论详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评论详情
     */
    @RequiresPermissions("blog:blogcomment:add")
    @Log(title = "评论详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BlogComment blogComment)
    {
    	blogComment.setUserId(getUserId());
    	blogComment.setCreateDate(new Date());
		//status:1为评论;2:为回复
		if (blogComment.getType()==null) {
			blogComment.setType(1);
		}
        return toAjax(blogCommentService.insertBlogComment(blogComment));
    }

    /**
     * 修改评论详情
     */
    @GetMapping("/edit/{commentId}")
    public String edit(@PathVariable("commentId") Long commentId, ModelMap mmap)
    {
        BlogComment blogComment = blogCommentService.selectBlogCommentById(commentId);
        mmap.put("blogComment", blogComment);
        return prefix + "/edit";
    }

    /**
     * 修改保存评论详情
     */
    @RequiresPermissions("blog:blogcomment:edit")
    @Log(title = "评论详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BlogComment blogComment)
    {
        return toAjax(blogCommentService.updateBlogComment(blogComment));
    }

    /**
     * 删除评论详情
     */
    @RequiresPermissions("blog:blogcomment:remove")
    @Log(title = "评论详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(blogCommentService.deleteBlogCommentByIds(ids));
    }
}
